﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace GUI
{
    public partial class FormTheoDoiBH : Window
    {
        public FormTheoDoiBH()
        {
            InitializeComponent();
            hoiThoat = false;
        }
        private void Laydulieu()
        {
            string chuoi =cbbNgay.Text;
            var ngay = chuoi.Split('/');
            var st = new DateTime(int.Parse(ngay[1]), int.Parse(ngay[0]), 1);
            OleDbDataAdapter da = BUS.BaoCaoDiemBUS.TheoDoiDonHang(st);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dataGridView1.Columns.Clear();
            dataGridView1.DataSource = ds.Tables[0];
            dataGridView1.Columns[0].HeaderText = "Mã ĐH";
            dataGridView1.Columns[1].HeaderText = "Ngày ĐH";
            dataGridView1.Columns[1].DefaultCellStyle.Format = "dd/MM/yyyy";
            dataGridView1.Columns[2].Visible = false;
            dataGridView1.Columns[3].HeaderText = "Tên SP";
            dataGridView1.Columns[4].HeaderText = "Số lượng";
            dataGridView1.Columns[5].HeaderText = "Đơn giá";
            dataGridView1.Columns[6].HeaderText = "Thành tiền";
            dataGridView1.Columns[7].HeaderText = "Nhận hàng";
            dataGridView1.Columns[8].HeaderText = "Còn lại";
            dataGridView1.Columns[9].HeaderText = "Ghi chú";


        }
        private void FormTheoDoiBH_Load(object sender, EventArgs e)
        {
            for (int i = 1; i <= 12; i++)
            {
                DateTime st = new DateTime(DateTime.Now.Year, i, 1);
                string ng = st.ToString("MM/yyyy");
                this.cbbNgay.Items.Add(ng);
                st = st.AddMonths(i);
            }
            cbbNgay.SelectedItem = cbbNgay.Items[DateTime.Now.Month - 1];
            Laydulieu();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnXem_Click(object sender, EventArgs e)
        {
            Laydulieu();
        }

        private void btnXuat_Click(object sender, EventArgs e)
        {
            XuatExcel(dataGridView1, "TheoDoiDonDatHang");
        }
                
    }
}
